import * as XLSX from 'xlsx';

export const generateExcelTemplate = () => {
  // Define the headers based on the labels
  const headers = [
    '语言版本', '学校', '院系', '专业编码', '专业名称', '专业简称',
    '领域', '学制（最短）', '学制（最长）', '是否接受Part-time','学费', '专业介绍',
    '申请频次（每年）', '申请时间', '专业课程', '本科学历',
    '工作经验', '雅思', '托福', '美国研究生入学考试',
    '是否需要面试'
  ];

  // Create worksheet with headers
  const ws = XLSX.utils.aoa_to_sheet([headers]);

  // Create workbook and append worksheet
  const wb = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(wb, ws, '专业信息模板');

  // Generate buffer
  const excelBuffer = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });

  // Create Blob and download
  const blob = new Blob([excelBuffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
  const url = URL.createObjectURL(blob);
  const link = document.createElement('a');
  link.href = url;
  link.download = '专业信息导入模板.xlsx';
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
  URL.revokeObjectURL(url);
};
